﻿using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace time
{
    [TestFixture]
    public class vancl_my1
    {
        private ISelenium selenium;
        private StringBuilder verificationErrors;
        //private StringBuilder error;

        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.vancl.com/");
            selenium.Start();
            verificationErrors = new StringBuilder();
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                //selenium.Stop();
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        ///测试超链是否能打开
        /// </summary>
        [Test]
        public void t1()
        {
            selenium.Open("http://my.vancl.com");
            selenium.WindowMaximize();
            //selenium.WaitForPageToLoad("30000");
            Thread.Sleep(5000);

            denglu();

            string stra = common.JsHelp.geta();
            String[] a = selenium.GetEval(stra).Split(','); // Split the string.

            foreach (var item in a)
            {
                try
                {
                    if (item.IndexOf(@"http://my.vancl.com") != -1)
                    {
                        selenium.Open(item);
                        System.Threading.Thread.Sleep(2000);

                        if (!selenium.IsElementPresent("//title"))
                        {
                            Console.Write(selenium.GetLocation() + " no title \n\r");
                        }
                        //selenium.GoBack();
                    }
                }
                catch (Exception ee)
                {
                    common.LogHelp.writelog(ee.ToString());

                    continue;
                }
            }
        }

        /// <summary>
        ///
        /// </summary>
        private void denglu()
        {
            //https://login.vancl.com/Login/Login.aspx
            selenium.Open("https://login.vancl.com/Login/Login.aspx");
            selenium.WindowMaximize();
            Thread.Sleep(4000);
            //selenium.WaitForPageToLoad("30000");
            string username = "zz130750@163.com";
            string password = "111111";
            selenium.Type("id=vanclUserName", username);
            selenium.Type("id=vanclPassword", password);
            selenium.Click("id=vanclLogin");
            System.Threading.Thread.Sleep(2000);
            //if (selenium.IsElementPresent("id=vanclUserName"))
            //{
            //    //Console.Write("true");
            //    //if ("https://login.vancl.com/Login/Login.aspx?http://my.vancl.com/" == selenium.GetLocation())
            //    //{
            //    //    if (selenium.IsElementPresent("id=vanclUserName"))
            //    //    {
            //    //        string username = "zz130750@163.com";
            //    //        string password = "111111";
            //    //        selenium.Type("id=vanclUserName", username);
            //    //        selenium.Type("id=vanclPassword", password);
            //    //        selenium.Click("id=vanclLogin");

            //    //        Thread.Sleep(2000);
            //    //        if (selenium.IsElementPresent("id=DropTitle"))
            //    //        {
            //    //            selenium.Click("id=DropTitle");
            //    //        }
            //    //        Thread.Sleep(5000);
            //    //    }
            //    //    //Console.Write("true");
            //    //}
            //}
        }

        [Test]
        public void t2()
        {
            try
            {
                denglu();

                selenium.Open("http://my.vancl.com/1/Usercenter/Edit_UserInfo.aspx");
                selenium.WindowMaximize();
                Thread.Sleep(5000);

                selenium.Type("id=TrueName", "qqq");
                selenium.Type("id=NewUserName", "qqq");
                selenium.Type("id=Mobile", "13681111111");
                selenium.Select("id=Province", "label=北京");
                selenium.Select("id=City", "label=北京市");
                selenium.Click("css=option[value=\"%e5%8c%97%e4%ba%ac%e5%b8%82\"]");
                selenium.Select("id=Area", "label=密云县");
                selenium.Click("css=option[value=\"%e5%af%86%e4%ba%91%e5%8e%bf\"]");
                selenium.Type("id=Address", "111111111111111111111111111");
                selenium.Type("id=PostalCode", "11");
                selenium.Type("id=PostalCode", "101500");
                selenium.Click("name=my_EditUserInfo_eu_btnSave");

                //selenium.WaitForPageToLoad("30000");
                Thread.Sleep(10000);
                //string s=selenium.GetAlert();
            }
            catch (Exception ee)
            {
                common.LogHelp.writelog(ee.ToString());
            }
            //Console.WriteLine(s);
        }

        [Test]
        public void t3()
        {
            try
            {
                denglu();

                //http://my.vancl.com/Avatar/Index/0
                selenium.Open("http://my.vancl.com/Avatar/Index/0");
                selenium.WindowMaximize();
                Thread.Sleep(5000);

                selenium.Click("id=AvatarType2");
                Thread.Sleep(2000);

                selenium.Click("//img[contains(@src,'http://user.vanclimg.com/myavatar/VT/pic2.jpg')]");
                Thread.Sleep(2000);

                selenium.Click("id=OK");
                Thread.Sleep(3000);

                selenium.Click("css=button[type=\"button\"]");
                Thread.Sleep(3000);

                selenium.Click("name=my_avatar_change_return");
                Thread.Sleep(3000);

                selenium.WaitForPageToLoad("30000");
               
            }
            catch (Exception ee)
            {
                common.LogHelp.writelog(ee.ToString());
            }
            //Console.WriteLine(s);
        }


    }
}